package com.zqx.service.impl;

import cn.hutool.crypto.digest.DigestUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zqx.mapper.UserMapper;
import com.zqx.domain.User;
import com.zqx.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Objects;

@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User>implements UserService {

    @Autowired
    private UserMapper userMapper;
    @Override
    public boolean login(String username, String password) {
        //条件构造器：MP用来查询一些特殊的字段
        QueryWrapper<User> qw = new QueryWrapper<>();
        qw.eq("username", username);
        User user = userMapper.selectOne(qw);
        if(user==null){
            return false;
        }
        //md5加密-信息摘要算法（密码散列函数）只能单向加密，不能解密
        String s = DigestUtil.md5Hex(password);
        String passwordx = user.getPassword();
        if (Objects.equals(s, passwordx)){
            return true;
        }else {
            return false;
        }
    }
}
